Skip to content

fix(ts): a .tsx call takes no lone method of its name past a .ts one - #3500

Closed
inth3shadows wants to merge 1 commit into
colbymchenry:mainfrom
inth3shadows:fix/3443-tsx-lone-guess
Closed

inth3shadows wants to merge 1 commit into
colbymchenry:mainfrom
inth3shadows:fix/3443-tsx-lone-guess

Conversation

@inth3shadows

Copy link
Copy Markdown
Contributor

Fixes #3443

What

In a .tsx file, a method call on a value codegraph can't type was linked to the only .tsx method of that name, even when a .ts file has a method of the same name. On excalidraw this sent 27 scene.mutateElement(…) calls in components (for example Stats/Angle.tsx#L49) to App.mutateElement in App.tsx. The compiler resolves them to Scene.mutateElement in scene.ts. The same thing happened from a .ts caller past a .tsx method.

Those calls now link nothing instead of the wrong method. The issue's destructured and plain callers no longer call App.mutateElement, and annotated still calls Scene.mutateElement at 0.9.

How

Name matching keeps TypeScript and TSX apart on purpose (#1662), so the by-name step sets a .ts method aside for a .tsx caller. The .tsx method left over was then taken as "the only method of the name" at 0.7. Now that guess is skipped when a method of the name in the other of the two languages:

What stays as on main:

  • Receiver-name scoring among several candidates, and a single candidate that is scored rather than guessed.
  • Typed receivers.
  • Callers with no method of the name in the other language.
  • JavaScript, JSX, Vue, Svelte and Astro callers.

Designs I tried and dropped during review:

  • Treating .ts and .tsx as one language in the by-name step. fix(resolution): don't believe a bare-name call across language families #1662 separated them because a name-only pick across the two went to the wrong declaration more often than to the right one.
  • Counting every method of the name in the other language. A React lifecycle render, a function-local class, an interface the lone class implements, or a test helper outside the test suites made correct edges disappear.
  • Marking the candidates "narrowed" up front. That also turned off the receiver-name scoring for a single reachable candidate (cache.aadd() → BaseCache). The check now gates only the lone guess.
  • Applying it to the whole JavaScript family. That removed edges in mixed .js/.ts and Vue projects, which nothing here measured.

Measured (base 3c230869878559f3f96bf5580b2d2c66dcf138e7 vs this branch, CODEGRAPH_KERNEL=0, Node 22, Linux x64)

  • __tests__/ts-tsx-lone-guess.test.ts: 17/17 pass. On main, the 4 tests that check a removed guess fail and the other 13 pass.
  • excalidraw dd2f8fc32b92cbf56f4abee6a0cf3b14681b4b55: 31 calls edges removed, none added. ky 3541888878c4d303a8bc2ad61815f4e048f55a5d and express 43fca52d28a422c8be48fd489cbd4f2d6152bab6: no edge changes.
  • Full suite on the final tree: 961 files and 11,517 tests passed, and 9 tests in 3 files failed: daemon-proof, prompt-hook-daemon and prompt-hook-daemon-busy. Those 9 fail the same way on main here, where the prompt hook can't reach the daemon under umask 0002 (Prompt hook: never reaches the running daemon when the umask is 0002 (Ubuntu's default) #3417). tsc --noEmit exits 0. Tested on Linux only.
  • Compatibility: no output or command changes; re-index TypeScript projects to drop the old edges.

Checked with graph-assay

I maintain graph-assay. Its issue-3443 fixture reads BROKEN on main (3c230869). On this branch it reads CHANGED: the two wrong edges are gone, and the two right ones (to Scene.mutateElement) are still missing, because this change removes a guess and adds no typing. No other fixture verdict changed.

Side effects on excalidraw, checked against scip-typescript:

  • 27 scene.mutateElement(…) → App.mutateElement, all wrong (the compiler resolves Scene#mutateElement).
  • App.pan.ts#L129 app.focusContainer() → the AppClassProperties.focusContainer interface member: wrong. The compiler resolves App#focusContainer, a .tsx method of the same name.
  • TTDstreamFetch.test.ts#L17 controller.close() → LaserPointer.close: wrong. The compiler resolves the DOM's ReadableStreamDefaultController#close.
  • excalidraw-app/App.tsx#L1069 and AppMainMenu.tsx#L74 excalidrawAPI?.refresh() → App.refresh: the compiler records no reference at either site. AppTextTool.refresh in App.textTool.ts is a second method of that name, so the guess is no longer taken.
node bin/graph-assay replay /path/to/codegraph/dist/bin/codegraph.js issue-3443

Known limits

  • The calls this fixes now link nothing rather than the right method. Linking Scene.mutateElement needs the receiver's type, from a destructured props parameter, const { scene } = app or a callback type. That is a separate change.
  • With several candidates, receiver-name scoring still sees only the caller's own language: a .tsx SceneView.mutateElement can win over Scene.mutateElement in scene.ts.
  • JavaScript, JSX, Vue, Svelte and Astro callers keep the lone guess past a method of the name in another of those languages.
  • A class whose head names a type the resolver can't follow — implements a type alias, a global declare interface from a .d.ts, or extends Mix(Base) — isn't recognised as sharing a hierarchy with the declaration it implements. Its lone method then loses the guess when that declaration is in the other language.
  • The check repeats the by-name step's filters for the other language's methods. A later change to those filters needs the same change there; the new tests cover each part.

Name matching keeps TypeScript and TSX apart (1662), so for a .tsx
caller a .ts class's method of the name was set aside, and the one
.tsx method left was taken as the only method of the name at 0.7.
On excalidraw that linked 27 scene.mutateElement(...) calls in .tsx
files to App.mutateElement, where the compiler resolves
Scene.mutateElement in scene.ts. The same held from a .ts caller
past a .tsx method.

The lone guess is now skipped when a method of the name in the
other of the two languages would have passed the by-name filters
(test files, dispatched view actions, a receiver's declared type,
lexical reach, React lifecycle methods, test constructor functions)
and is not in the lone method's own class hierarchy (an interface or
abstract method it implements, or an override). Receiver-name
scoring is untouched. JavaScript, JSX, Vue, Svelte and Astro callers
are unchanged.

Fixes 3443.
inth3shadows added a commit to inth3shadows/codegraph that referenced this pull request Nov 27, 2026
inth3shadows added a commit to inth3shadows/codegraph that referenced this pull request Nov 27, 2026
@inth3shadows

Copy link
Copy Markdown
Contributor Author

Closing: #3524 landed this fix on 2026-11-29. Thanks for carrying it.

inth3shadows added a commit to inth3shadows/codegraph that referenced this pull request Dec 3, 2026
…1.6.7)

Took upstream's side where it merged our PRs as its own:
- colbymchenry#3309 named pipes -> upstream colbymchenry#3521 (fork's readRegularFile and the
  config-file-fifo test removed; the compile_commands.json read keeps
  upstream's readRegularFileSync, which colbymchenry#3521 did not cover)
- colbymchenry#3418 prompt hook under umask 0002 -> upstream colbymchenry#3523 (fork test removed)
- colbymchenry#3499/colbymchenry#3500 canvas context and .tsx lone guess -> upstream colbymchenry#3524 (fork
  code and ts-tsx-lone-guess test removed; the calls colbymchenry#3524 drops are
  colbymchenry#3607, its missed case colbymchenry#3608)
- colbymchenry#3226 variance -> upstream colbymchenry#3520
- the fork's Java wildcard static-call copy (colbymchenry#3138) -> upstream's own
  visibility check; the fork test still passes on upstream code

Kept fork-only: Bash, the CommonJS missing member, member call on an imported
function, the TypeScript grammar fork, the short MCP instructions (colbymchenry#1529), and
import-type default exports (export * never forwards a default; an explicit
default with none resolvable links nothing).

Kernel build.rs/langs.rs: union of the vendored TypeScript grammar and
upstream's new vendored grammars.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeScript: a parameter typed only by its callback type links its method calls to another class's method

1 participant